package heven.holt.wan.android.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import androidx.navigation.findNavController
import dagger.hilt.android.AndroidEntryPoint
import heven.holt.library.base.BaseFragment
import heven.holt.wan.android.MainFragmentDirections
import heven.holt.wan.android.databinding.FragmentUserBinding
import heven.holt.wan.android.extensions.navigationLoginIntercept
import heven.holt.wan.android.viewmodel.UserViewModel

@AndroidEntryPoint
class UserFragment : BaseFragment<FragmentUserBinding>() {
    private val userViewModel: UserViewModel by activityViewModels()

    override fun bindViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): FragmentUserBinding = FragmentUserBinding.inflate(inflater, container, false)

    override fun initView() {
    }

    override fun initData() {
        binding.lifecycleOwner = viewLifecycleOwner
        binding.userInfo = userViewModel.userInfoLiveData
        binding.handler = Handlers()
    }

    inner class Handlers {
        fun intentLogin(view: View) {
            if (userViewModel.isLogin()) return
            val direction =
                MainFragmentDirections.actionMainFragmentToLoginFragment()
            view.findNavController().navigate(direction)
        }

        fun intentMyCoin(view: View) {
            val direction = MainFragmentDirections.actionMainFragmentToMyCoinFragment()
            view.navigationLoginIntercept(direction)
        }

        fun intentCustomAnimation(view: View) {
            val direction = MainFragmentDirections.actionMainFragmentToCustomAnimationFragment()
            view.navigationLoginIntercept(direction)
        }
    }
}